<HTML><HEAD> <!-- --------------- Password Fields --------------- --> <SCRIPT LANGUAGE="JavaScript"><!-- hide from old browsers /* THE JAVASCRIPT COOKBOOK by Erica Sadun, webrx@mindspring.com Copyright (c)1998 by Charles River Media. All Rights Reserved. This applet can only be re-used or modifed by license holders of the JavaScript Cookbook CD-ROM. Credit must be given in the source code and this copyright notice must be maintained. If you do not hold a license to the JavaScript Cookbook, you may NOT duplicate or modify this code for your own use. Use at your own risk. No warranty is given or implied of the suitability of this applet for any specific application. Neither Erica Sadun nor Charles River Media will be held responsible for any unwanted effects due to the use of this applet or any derivative. */ function entered(fieldName) { var formNum = 0; if(fieldName.indexOf("2") != -1) formNum = 1; var val = eval("document.forms["+formNum+"]."+fieldName+".value"); var len = val.length; alert("You typed \"" + val + "\" of length " + len) eval("document.forms["+formNum+"]."+fieldName+".focus()"); eval("document.forms["+formNum+"]."+fieldName+".select()"); } <!-- done hiding --></SCRIPT></HEAD> <BODY bgcolor="ffffff" link="0000ff" vlink="770077" onLoad='document.forms[0].PW.focus()'> <FONT COLOR="007777"><H1><IMG SRC="../GRAFX/UTENS.JPG" WIDTH=80 HEIGHT=50 ALIGN = LEFT>Password Values</H1></FONT> <FONT COLOR="770000"><BLOCKQUOTE> These fields both look like ordinary text fields, but the first is not. Type some text into the first field; only "dots" appear. Password values can be read from scripts, even if they can't be seen in the window. </BLOCKQUOTE></FONT> <FONT SIZE=4><CENTER><FORM onSubmit='entered("PW")' > <INPUT TYPE="PASSWORD" NAME="PW" onChange='entered("PW")'><INPUT TYPE="button" VALUE="Use this if 'Return' doesn't work" onClick='entered("PW")'> </FORM></CENTER></FONT><p> <FONT SIZE=4><CENTER><FORM onSubmit='entered("PW2")' onChange='entered("PW2")'> <INPUT TYPE="TEXT" NAME="PW2"> <INPUT TYPE="button" VALUE="Use this if 'Return' doesn't work" onClick='entered("PW2")'> </FORM></CENTER></FONT> <FONT COLOR="007777"><H2>Discussion</H2></FONT><FONT SIZE=4> Sometimes you wish to have the user type a password or some other secure information into a form. You still need to be able to evaluate it (or have some server-side agent evaluate it), so you're not blocked from accessing the contents in a script. (This is not as insecure as it might seem. Users cannot determine what was typed in the password field by viewing the script in the browser.)<p> Netscape Navigator versions prior to 3.0 may not allow you to access the password information. You will need to check for these browsers and have your script adjust accordingly. <FONT COLOR="770000"><PRE> function entered(fieldName) { var formNum = 0; if(fieldName.indexOf("2") != -1) formNum = 1; var val = eval("document.forms["+formNum+"]."+fieldName+".value"); var len = val.length; alert("You typed \"" + val + "\" of length " + len) eval("document.forms["+formNum+"]."+fieldName+".focus()"); eval("document.forms["+formNum+"]."+fieldName+".select()"); } <FORM onSubmit='entered("PW"); return false'> <INPUT TYPE="PASSWORD" NAME="PW"> </FORM><P> <FORM onSubmit='entered("PW2"); return false'> <INPUT TYPE="TEXT" NAME="PW"> </FORM> </PRE></FONT> <h5>Copyright ©1998 by Charles River Media, All Rights Reserved</h5> </BODY> </HTML>